<!-- photoinfo 组件 -->
<template>
  <div class="photoinfo-container">
    <!-- 顶部标题区域 -->
    <h3 class="title" v-text="photoinfo.title"></h3>
    <p class="subtitle">
      <span>发表时间： {{ photoinfo.add_time | dataFormat }}</span>
      <span>点击： {{ photoinfo.click }}次</span>
    </p>
    <hr />
    <!-- 缩略图区域 -->
    <div class="thumbnail">
      <vue-preview :slides="thumbList"></vue-preview>
    </div>
    <!-- 图片内容 -->
    <div class="content" v-html="photoinfo.content"></div>
    <!-- 评论区域 -->
    <comment :id="this.id"></comment>
  </div>
</template>

<script>
import comment from "../subcomponent/comment.vue";
export default {
  data() {
    return {
      id: this.$route.params.id, // 列表图片id
      photoinfo: {}, // 图片详情
      thumbList: [] // 缩略图
    };
  },

  created() {
    this.getPhotoInfo();
    this.getThumbList();
  },

  methods: {
    getPhotoInfo() {
      // 获取图片详情
      this.axios.get("api/getimageinfo/" + this.id).then(resp => {
        if (resp.data.status === 0) {
          // 获取数据成功
          this.photoinfo = resp.data.message[0];
        } else {
          // 获取失败
          Toast("获取数据失败");
        }
      });
    },
    getThumbList() {
      // 获取图片列表
      this.axios.get("api/getthumimages/" + this.id).then(resp => {
        if (resp.data.status === 0) {
          // 获取数据成功
          let data = resp.data.message;
          data.forEach(item => {
            item.w = 600; //设置以大图浏览时的宽度
            item.h = 400; //设置以大图浏览时的高度
            item.src.width = "50px";
            item.src.height = "50px";
            item.msrc = item.src; // 小图
          });
          this.thumbList = data;
        } else {
          // 获取失败
          Toast("获取数据失败");
        }
      });
    }
  },

  components: {
    comment
  }
};
</script>

<style lang='scss' scoped>
.photoinfo-container {
  padding: 0 5px;
  .title {
    margin: 16px 0;
    font-size: 16px;
    text-align: center;
    color: skyblue;
  }
  .subtitle {
    font-size: 13px;
    color: #226aff;
    display: flex;
    justify-content: space-between;
  }
  .content {
    font-size: 13px;
    line-height: 30px;
  }
  .thumbnail {
    /deep/ .my-gallery {
      display: flex;
      flex-wrap: wrap;
      figure {
        width: 30%;
        margin: 5px;
        img {
          width: 100%;
          box-shadow: 0 0 6px #999;
          border-radius: 5px;
        }
      }
    }
  }
}
</style>